package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/6.
 */
@HttpInlet(Conn.USERINFO_INTEGRAL)
public class UserInfoIntegralRecordGet extends BaseAsyGet<UserInfoIntegralRecordGet.IntegralRecordEntity> {

    public String user_id, type;

    public UserInfoIntegralRecordGet(AsyCallBack<IntegralRecordEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected IntegralRecordEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            IntegralRecordEntity integralRecordEntity = new IntegralRecordEntity();

            JSONArray array = object.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject recordObject = array.optJSONObject(i);

                IntegralRecord integralRecord = new IntegralRecord();

                integralRecord._id = recordObject.optString("_id");
                integralRecord.user_id = recordObject.optString("user_id");
                integralRecord.integral = recordObject.optString("integral");
                integralRecord.type = recordObject.optString("type");
                integralRecord.posttime = recordObject.optString("posttime");
                integralRecord.note = recordObject.optString("note");

                integralRecordEntity.recordList.add(integralRecord);

            }

            return integralRecordEntity;

        }

        return null;

    }

    public class IntegralRecordEntity {

        public List<IntegralRecord> recordList = new ArrayList<>();

    }

    public class IntegralRecord {

        public String _id, user_id, integral, type, posttime, note;

    }


}
